<template>
  <div>
    <home-header ></home-header>
    <home-swiper></home-swiper>
    <home-icons :iconList='iconList'></home-icons>
    <home-recommend :List='recommendList'></home-recommend>
    <home-weekend :List='weekendList'></home-weekend>
  </div>
</template>

<script>
import HomeHeader from './components/Header'
import HomeSwiper from './components/Swiper'
import HomeIcons from './components/Icons'
import HomeRecommend from './components/Recommend'
import HomeWeekend from './components/Weekend'
import {getHome} from '@/api'
export default {
    name:'Home',
    data (){
      return {
        lastCity:'',
        iconList:[],
        recommendList:[],
        weekendList:[],

      }
    },
    components:{
      HomeHeader,HomeSwiper,HomeIcons,HomeRecommend,HomeWeekend
    },
    mounted(){
      this.lastCity = this.city
      this.getHomeInfo()
    },
    activated(){
      //keep allive 生命周期可执行
      if (this.lastCity !== this.city) {
        this.lastCity = this.city
        this.getHomeInfo()
        console.log('切换城市重新调接口刷新');
      }

    },
    methods:{
      getHomeInfo(){
        getHome().then(this.getHomeInfoSucc)
      },
      getHomeInfoSucc(res){
        if (res.msg == 200 && res.data) {
         this.iconList = res.data.iconList,
         this.recommendList = res.data.recommendList
         this.weekendList = res.data.weekendList
        }
      }
    }
}
</script>

<style>

</style>